<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta http-equiv=X-UA-Compatible content="IE=edge"/>
    <meta name=viewport content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>所教学生信息</title>
    <link rel="stylesheet" href="../css/element/index.css"/>
    <link rel="stylesheet" href="../css/main.css"/>
    <link rel="stylesheet" href="../css/header.css"/>
    <link rel="stylesheet" href="../css/sidebar.css"/>
    <link rel="stylesheet" href="../css/right.css"/>
</head>
<body>
<!--课程-->
<div id="app">
    <!-- 表格开始 -->
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-s-grid"></i>所教学生信息表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>

        <!-- 表主体开始 -->
        <div class="container">
            <!-- 弹窗开始 -->
            <!--编辑课程信息 -->
            <el-dialog title="编辑成绩信息" :visible.sync="dialogVisible">
                <el-form :model="grade">
                    <el-form-item label="成绩" :label-width="formWidth">
                        <el-input v-model="grade.grade" autocomplete="off"></el-input>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogVisible = false" size="small">取 消</el-button>
                    <el-button type="primary" @click="save" size="small">确 定</el-button>
                </div>
            </el-dialog>
            <!-- 弹窗结束 -->
            <!-- 表格数据开始 -->
            <el-table ref="multipleTable"
                      :data="tableData" class="table"
                      tooltip-effect="dark" style="width: 100%"
                      @selection-change="handleSelectionChange">
                <!-- 多选框所在的列 -->
                <el-table-column
                        type="selection"
                        width="55">
                </el-table-column>
                <el-table-column
                        prop="cno"
                        label="课程号"
                        width="140">
                </el-table-column>
                <el-table-column
                        prop="cname"
                        label="课程名"
                        width="200">
                </el-table-column>
                <el-table-column
                        prop="sname"
                        label="学生姓名"
                        width="140">
                </el-table-column>
                <el-table-column
                        prop="dengJi"
                        label="等级"
                        width="140">
                </el-table-column>
                <el-table-column
                        prop="sclass"
                        label="班级"
                        width="140">
                </el-table-column>
                <el-table-column
                        prop="cgrade"
                        label="学生成绩"
                        width="140">
                </el-table-column>
                <el-table-column
                        label="操作"
                        width="150">
                    <template slot-scope="scope">
                        <el-button size="mini" type="success" plain @click="showEditWindow(scope.row.id)">添加成绩
                        </el-button>
                        <el-button size="mini" type="info" plain @click="update(scope.row.id)">修改成绩</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 表格数据结束 -->

            <!-- 分页开始 -->
            <div class="pagination">
                <el-pagination
                        @size-change="fetchData"
                        @current-change="fetchData"
                        :current-page.sync="currentPage"
                        :page-sizes="pageSizes"
                        :page-size.sync="pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </div>
            <!-- 分页结束 -->
        </div>
        <!-- 表主体结束 -->
    </div>
    <!-- 表格结束 -->
</div>


<script src="../js/vue.min.js"></script>
<script src="../js/element.js"></script>
<script src="../js/axios.min.js"></script>
<script src="../js/basic.js"></script>
<script>
    new Vue({
        el: '#app',
        data: {
            tableData: [],
            multipleSelection: [],
            dialogVisible: false,
            grade: {
                id:''
            },
            formWidth: '120px',
            currentPage: 1, // 当前页码
            pageSize: 5, // 每页显示记录数
            pageSizes: [2, 3, 5, 10, 15, 20], // 选择每页显示数
            total: 0, // 总记录数
            formMap: {}, // 用于搜索的对象
        },
        created: function () {
            // 异步获取数据
            this.fetchData();
        },
        computed: {//计算
        },
        methods: {
            // 点击添加显示编辑窗口
            showEditWindow(id) {
                this.grade = {};
                this.dialogVisible = true;
                this.grade.id = id;
            },
            // 获取数据
            fetchData() {
                _this = this;
                this.formMap.dengJi = localStorage.getItem("dengJi");
                this.formMap.tNo = localStorage.getItem("tNo");
                axios.post(`${httpUrl}/teacher/studentList?page=${this.currentPage}&size=${this.pageSize}`,this.formMap)
                    .then(res => {
                        console.log(res)
                        _this.tableData = res.data.row;
                        _this.total = res.data.total;
                        console.log(res)
                    }).catch(err => {
                    this.$message({
                        showClose: true,
                        message: err.message,
                        type: 'error'
                    });
                });
            },
            // 添加成绩
            save(){
                _this = this;
                axios.post(`${httpUrl}/teacher/addGrade`, this.grade)
                    .then(res => {
                        let r = res.data;
                        if (r.code !== 200) {
                            this.$message({
                                showClose: true,
                                message: r.msg,
                                type: 'error'
                            });
                        } else {
                            this.$message({
                                showClose: true,
                                message: r.msg,
                                type: 'success'
                            });
                            // 关闭弹窗
                            _this.dialogVisible = false;
                            _this.grade = {}
                            // 重新获取一次数据
                            _this.fetchData();
                        }
                    });
            },
            // 点击修改显示编辑窗口
            update(id) {
                _this = this;
                axios.get(httpUrl + '/teacher/getGradeById?id=' + id)
                    .then(res => {
                        // 显示编辑窗口
                        _this.dialogVisible = true
                        // 给编辑窗口设置值
                        _this.grade = res.data.data
                        //重新获取一次数据
                        _this.fetchData();
                    }).catch(er => {
                    this.$message({
                        showClose: true,
                        message: er.message,
                        type: 'error'
                    });
                })
            },
            // 搜索
            handleSelectionChange(val) {
                this.multipleSelection = val;
            }
        }
    })
</script>
</body>
</html>